/*     */ package com.zimbra.cs.account.callback;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.account.AttributeCallback;
/*     */ import com.zimbra.cs.account.AttributeCallback.MultiValueMod;
/*     */ import com.zimbra.cs.account.Entry;
/*     */ import com.zimbra.cs.httpclient.URLUtil;
/*     */ import java.net.MalformedURLException;
/*     */ import java.net.URL;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class MtaAuthHost
/*     */   extends AttributeCallback
/*     */ {
/*     */   public void preModify(CallbackContext context, String attrName, Object value, Map attrsToModify, Entry entry)
/*     */     throws ServiceException
/*     */   {
/*  45 */     AttributeCallback.MultiValueMod mod = multiValueMod(attrsToModify, "zimbraMtaAuthHost");
/*  46 */     Set<String> values = mod.valuesSet();
/*     */     
/*  48 */     if (mod.adding())
/*     */     {
/*  50 */       List<String> urlsToAdd = new ArrayList();
/*  51 */       for (String authHost : values) {
/*  52 */         String authUrl = URLUtil.getMtaAuthURL(authHost);
/*  53 */         urlsToAdd.add(authUrl);
/*     */       }
/*  55 */       if (urlsToAdd.size() > 0) {
/*  56 */         attrsToModify.put("+zimbraMtaAuthURL", urlsToAdd.toArray(new String[urlsToAdd.size()]));
/*     */       }
/*     */       
/*     */     }
/*  60 */     else if (mod.replacing())
/*     */     {
/*  62 */       List<String> urls = new ArrayList();
/*  63 */       for (String authHost : values) {
/*  64 */         String authUrl = URLUtil.getMtaAuthURL(authHost);
/*  65 */         urls.add(authUrl);
/*     */       }
/*  67 */       if (urls.size() > 0) {
/*  68 */         attrsToModify.put("zimbraMtaAuthURL", urls.toArray(new String[urls.size()]));
/*     */       }
/*     */       
/*     */     }
/*  72 */     else if (mod.removing())
/*     */     {
/*     */ 
/*     */ 
/*     */ 
/*  77 */       if ((!context.isCreate()) && (entry != null)) {
/*  78 */         Set<String> curUrls = entry.getMultiAttrSet("zimbraMtaAuthURL");
/*  79 */         List<String> urlsToRemove = new ArrayList();
/*     */         
/*  81 */         for (String authHost : values) {
/*     */           try {
/*  83 */             String authUrl = URLUtil.getMtaAuthURL(authHost);
/*  84 */             if (curUrls.contains(authUrl)) {
/*  85 */               urlsToRemove.add(authUrl);
/*     */             }
/*     */           } catch (ServiceException e) {
/*  88 */             for (String curUrl : curUrls) {
/*     */               try {
/*  90 */                 URL url = new URL(curUrl);
/*  91 */                 String urlHost = url.getHost();
/*     */                 
/*     */ 
/*     */ 
/*  95 */                 if (authHost.equals(urlHost)) {
/*  96 */                   urlsToRemove.add(curUrl);
/*     */                 }
/*     */               } catch (MalformedURLException mue) {
/*  99 */                 urlsToRemove.add(curUrl);
/*     */               }
/*     */             }
/*     */           }
/*     */         }
/* 104 */         if (urlsToRemove.size() > 0) {
/* 105 */           attrsToModify.put("-zimbraMtaAuthURL", urlsToRemove.toArray(new String[urlsToRemove.size()]));
/*     */         }
/*     */         
/*     */       }
/*     */     }
/* 110 */     else if (mod.deleting())
/*     */     {
/* 112 */       attrsToModify.put("zimbraMtaAuthURL", null);
/*     */     }
/*     */   }
/*     */   
/*     */   public void postModify(CallbackContext context, String attrName, Entry entry) {}
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/callback/MtaAuthHost.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */